/**
 * 
 */
package com.wodsy.phoenix.apps.cms.homepage.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wodsy.phoenix.dataobject.base.Pager;
import com.wodsy.phoenix.dataobject.cms.model.IdxHotGoodsRecommended;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageHotGoodsService;

/**
 * @author bryan
 *
 */
@RequestMapping("/cmsHotGoods")
@Controller
public class CmsHomePageIndexHotGoodsController {
	private Logger logger = LoggerFactory.getLogger(CmsHomePageIndexHotGoodsController.class);
	@Autowired
	private CmsHomePageHotGoodsService cmsHomePageHotGoodsService;

	/**
     * 导向首页面
     *
     * @param request 请求
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(HttpServletRequest request) {
        return "/hotGoods";
    }
    
    /**
	 * 增加一条goods
	 */
    @RequestMapping(value = "/addOneHotGoods", method = RequestMethod.POST)
    @ResponseBody
    public void addOneHotGoods(IdxHotGoodsRecommended tHotGoodsRecommended){
		
		tHotGoodsRecommended.setCreateTime(new Date());
		
		cmsHomePageHotGoodsService.save(tHotGoodsRecommended);
		
	}
	/**
	 * 获取一条goods信息
	 */
    @RequestMapping(value = "/getOneHotGoods/{goodsId}", method = RequestMethod.GET)
    @ResponseBody
	public IdxHotGoodsRecommended getOneHotGoods(@PathVariable Integer goodsId){
		IdxHotGoodsRecommended goods = cmsHomePageHotGoodsService.get(goodsId);
		return goods;
	}
	/**
	 * 修改一条goods信息
	 */
    @RequestMapping(value = "/updateOneHotGoods", method = RequestMethod.POST)
    @ResponseBody
    public void updateOneHotGoods(IdxHotGoodsRecommended tHotGoodsRecommended){
		
		tHotGoodsRecommended.setUpdateTime(new Date());
		
		cmsHomePageHotGoodsService.updateHotGoodsRecommended(tHotGoodsRecommended);
		//.update(tHotGoodsRecommended);
		
	}
	/**
	 * 根据搜索条件查询goodsList
	 */
    @RequestMapping(value = "/getAllHotGoodsByOrder", method = RequestMethod.POST)
    @ResponseBody
	public Pager<IdxHotGoodsRecommended> getAllHotGoodsByOrder(int pageSize,int pageNo,IdxHotGoodsRecommended goodsreq){
		Pager<IdxHotGoodsRecommended> hotGoodsRec = new Pager<>();
		hotGoodsRec.setPageSize(pageSize);
		hotGoodsRec.setPageNo(pageNo);
		
		Pager<IdxHotGoodsRecommended> picPager = cmsHomePageHotGoodsService.searchHotGoodsRecByOrder(hotGoodsRec, goodsreq);
			
		return picPager;
	}
	/**
	 * 更新pic状态
	 * @param rgoodsId 推荐的id
	 */
    @RequestMapping(value = "/updatePicHotGoodsStatus", method = RequestMethod.POST)
    @ResponseBody
    public void updatePicHotGoodsStatus(Integer rgoodsId,Integer status){
		cmsHomePageHotGoodsService.updateGoodsRecommendedStatus(rgoodsId, status);
	}
	
	/**
	 * 更新picList状态
	 */
    @RequestMapping(value = "/updatePicHotGoodsStatusList", method = RequestMethod.POST)
    @ResponseBody
    public void updatePicHotGoodsStatusList(Integer[] list,Integer status){
		cmsHomePageHotGoodsService.updateGoodsRecommendedStatus(list, status);
	}
    
}
